import java.util.Arrays;

public class MyBitSet {
    public byte[] elem;
    private int usedSize;

    public MyBitSet(){
        this.elem = new byte[1];
    }

    public MyBitSet(int n){
        this.elem = new byte[n / 8 + 1];
    }

    public void set(int val){
        if(val < 0){
            throw new PosOutOfBoundsException();
        }
        int byteIndex = val / 8;
        int bitIndex = val % 8;
        if(byteIndex >= this.elem.length){
            this.elem = Arrays.copyOf(this.elem, byteIndex + 1);
        }
        this.elem[byteIndex] |= (1 << bitIndex);
        this.usedSize++;
    }

    public boolean get(int val){
        if(val < 0 || val / 8 >= this.elem.length){
            throw new PosOutOfBoundsException();
        }
        int byteIndex = val / 8;
        int bitIndex = val % 8;
        if(((this.elem[byteIndex] >> bitIndex) & 1) == 1){
            return true;
        }
        return false;
    }

    public void reset(int val){
        if(val < 0 || val / 8 >= this.elem.length){
            throw new PosOutOfBoundsException();
        }
        int byteIndex = val / 8;
        int bitIndex = val % 8;
        this.elem[byteIndex] &= ~(1 << bitIndex);
        this.usedSize--;
    }

    public int getUsedSize(){
        return this.usedSize;
    }
}
